/**
 * 路由相关 Mock 数据
 */

// 模拟后端返回的路由数据（扁平化格式，前端需要转换为树形结构）
const routes = [
  // 仪表板
  {
    id: 1,
    parentId: 0,
    path: '/dashboard',
    name: 'Dashboard',
    component: '/views/home/dashboard.vue',
    meta: {
      title: '仪表板',
      icon: 'Odometer',
      requiresAuth: true,
      keepAlive: true,
      order: 1
    }
  },
  
  // 系统管理
  {
    id: 2,
    parentId: 0,
    path: '/system',
    name: 'System',
    component: null,  // 父级菜单不需要组件
    redirect: '/system/user',
    meta: {
      title: '系统管理',
      icon: 'Setting',
      requiresAuth: true,
      order: 2
    }
  },
  {
    id: 21,
    parentId: 2,
    path: '/system/user',
    name: 'SystemUser',
    component: '/views/system/user/index.vue',
    meta: {
      title: '用户管理',
      icon: 'User',
      requiresAuth: true,
      keepAlive: true,
      order: 1
    }
  },
  {
    id: 22,
    parentId: 2,
    path: '/system/role',
    name: 'SystemRole',
    component: '/views/system/role/index.vue',
    meta: {
      title: '角色管理',
      icon: 'UserFilled',
      requiresAuth: true,
      keepAlive: true,
      order: 2
    }
  },
  {
    id: 23,
    parentId: 2,
    path: '/system/menu',
    name: 'SystemMenu',
    component: '/views/system/menu/index.vue',
    meta: {
      title: '菜单管理',
      icon: 'Menu',
      requiresAuth: true,
      keepAlive: true,
      order: 3
    }
  },
  
  // 用户中心
  {
    id: 3,
    parentId: 0,
    path: '/user',
    name: 'User',
    component: null,
    redirect: '/user/profile',
    meta: {
      title: '用户中心',
      icon: 'Avatar',
      requiresAuth: true,
      order: 3
    }
  },
  {
    id: 31,
    parentId: 3,
    path: '/user/profile',
    name: 'UserProfile',
    component: '/views/user/profile.vue',
    meta: {
      title: '个人资料',
      icon: 'UserFilled',
      requiresAuth: true,
      order: 1
    }
  },
  {
    id: 32,
    parentId: 3,
    path: '/user/setting',
    name: 'UserSetting',
    component: '/views/user/setting.vue',
    meta: {
      title: '账户设置',
      icon: 'Tools',
      requiresAuth: true,
      order: 2
    }
  },
  
  // 示例页面
  {
    id: 4,
    parentId: 0,
    path: '/example',
    name: 'Example',
    component: null,
    redirect: '/example/basic',
    meta: {
      title: '示例页面',
      icon: 'Document',
      requiresAuth: true,
      order: 4
    }
  },
  {
    id: 41,
    parentId: 4,
    path: '/example/basic',
    name: 'ExampleBasic',
    component: '/views/example/basic-usage.vue',
    meta: {
      title: '基础用法',
      icon: 'Document',
      requiresAuth: true,
      order: 1
    }
  },
  {
    id: 42,
    parentId: 4,
    path: '/example/dashboard',
    name: 'ExampleDashboard',
    component: '/views/example/dashboard.vue',
    meta: {
      title: '示例仪表板',
      icon: 'DataBoard',
      requiresAuth: true,
      order: 2
    }
  },
  {
    id: 43,
    parentId: 4,
    path: '/example/form',
    name: 'ExampleForm',
    component: '/views/example/form-page.vue',
    meta: {
      title: '表单页面',
      icon: 'EditPen',
      requiresAuth: true,
      order: 3
    }
  },
  
  // 关于系统
  {
    id: 5,
    parentId: 0,
    path: '/about',
    name: 'About',
    component: '/views/about/index.vue',
    meta: {
      title: '关于系统',
      icon: 'InfoFilled',
      requiresAuth: true,
      order: 5
    }
  }
]

// 根据角色过滤路由
function filterRoutesByRole(routes, roles) {
  // 如果是管理员，返回所有路由
  if (roles.includes('admin')) {
    return routes
  }
  
  // 其他角色只能访问部分路由
  return routes.filter(route => {
    // 示例：编辑员只能访问仪表板和用户中心
    if (roles.includes('editor')) {
      return [1, 3, 31, 32].includes(route.id)
    }
    return false
  })
}

export default [
  // 获取用户路由
  {
    url: '/api/auth/routes',
    method: 'get',
    response: ({ headers }) => {
      // 这里简化处理，实际应该根据 token 获取用户角色
      const roles = ['admin']  // 模拟管理员角色
      
      const userRoutes = filterRoutesByRole(routes, roles)
      
      return {
        code: 200,
        message: '获取成功',
        data: userRoutes
      }
    }
  },
  
  // 获取所有路由（用于菜单管理）
  {
    url: '/api/system/routes',
    method: 'get',
    response: () => {
      return {
        code: 200,
        message: '获取成功',
        data: routes
      }
    }
  }
]

